/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ig.util;

import ig.metrica.ui.PrincipalMetrica;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.swing.JOptionPane;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

/**
 *
 * @author jsanchez
 */
public class LogStream extends FilterOutputStream {


    private Logger logger = Logger.getLogger(LogStream.class);
    public LogStream(OutputStream aStream) {
        super(aStream);
        StringBuilder builder = new StringBuilder("");
        builder.append("******************************************************************************\n");
        builder.append("**\n");
        builder.append("** SI QUIERE VER EL DETALLE DE LA CONSOLA, IR A LA RUTA \\log\\server.log\n");
        builder.append("**\n");
        builder.append("******************************************************************************\n");
        System.out.println(builder);
        //JOptionPane.showMessageDialog(null, builder.toString());
        PropertyConfigurator.configure("log4j.properties");
    }

    public void write(byte b[]) throws IOException {
        String aString = new String(b);
        //aTextArea.append(aString);
        PrincipalMetrica.getInstance().texto.append(aString);
        //System.out.println("Metrica : " + aString);
        if(aString!=null && !aString.trim().isEmpty()){
            logger.info(aString);
        }
    }

    public void write(byte b[], int off, int len) throws IOException {
        String aString = new String(b, off, len);
        PrincipalMetrica.getInstance().texto.append(aString);
        //System.out.println("Metrica : " + aString);
        //aTextArea.append(aString);
        //if (logFile) {
        //    FileWriter aWriter = new FileWriter(fileName, true);
        //    aWriter.write(aString);
        //    aWriter.close();
        //}
        if(aString!=null && !aString.trim().isEmpty()){
            logger.info(aString);
        }
    }
}
